package com.demo.web;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("path")
public class PathController {

    // http://127.0.0.1:8080/mvc/path/abc
    @RequestMapping("/abc")
    public String path(){
        System.out.println("path");
        return "path";
    }
    // http://127.0.0.1:8080/mvc/path/info?name=张三&age=18
    // 传统的前端给后端传递参数的方式
    @RequestMapping("/info")
    public String path(@RequestParam("name")String name,@RequestParam("age")Integer age){
        System.out.println("info");
        return "path";
    }
    // 路径占位符传递参数
    // http://127.0.0.1:8080/mvc/path/desc/张三/18
    @RequestMapping("/desc/{name}/{age}")
    public String desc(@PathVariable("name")String name, @PathVariable("age")Integer age){
        System.out.println("desc");
        System.out.println("name = " + name);
        System.out.println("age = " + age);
        return "desc";
    }

}
